﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ListenMusic.Models.Reposistory.User;
using ListenMusic.Playlist_ServiceReference;
using System.ServiceModel;
namespace ListenMusic.Controllers.User
{
    public class PlaylistController : ApplicationController
    {
        //
        // GET: /Playlist/
      
        public PlaylistController()
        {
            
        }

        [Authorize(Roles = "websiteuser")]
        public ActionResult Index()
        {

            return View();
        }
        [Authorize(Roles = "websiteuser")]
        public JsonResult AddMusic(int songid, int plid)
        {
            Response.ContentType = "application/json";
            try
            {
                Favorite f = new Favorite();
                f.SongID = songid;
                f.PlaylistID = plid;
                bool res = _playlist.AddMusic_Into_Playlist(f);
                var message = "";
                if (res)
                {
                    message = "Thành công";
                }
                else
                {
                    message = "Thất bại";
                }
                return Json(message, JsonRequestBehavior.AllowGet);
                //if (res)
                //{
                //    return Redirect(returnURL);
                //}
                //else
                //{
                //    return View("~/Views/Shared/_Error.cshtml");
                //}
            }
            catch (FaultException ex)
            {
                //return View("~/Views/Shared/_Error.cshtml");
                throw ex;
            }

        }
        [Authorize(Roles = "websiteuser")]
        public JsonResult AddPlaylist(string playlistname)
        {
            Response.ContentType = "application/json";
            try
            {
             
                Playlist pl = new Playlist();
                pl.PlaylistName = playlistname;
                pl.Picture = "no_playlist_image.jpg";
                pl.UserName = Session["user"].ToString();
                bool res = _playlist.AddNewPlaylist(pl);
                var message = "";
                if (res)
                {
                    message = "Thành công";
                }
                else
                {
                    message = "Thất bại";
                }
                return Json(message, JsonRequestBehavior.AllowGet);
                //if (res)
                //{
                //    return Redirect(returnURL);
                //}
                //else
                //{
                //    return View("~/Views/Shared/_Error.cshtml");
                //}
            }
            catch (FaultException ex)
            {
                //return View("~/Views/Shared/_Error.cshtml");
                throw ex;
            }
        }
    }
}
    